//
//  LLBaseViewController.m
//  LLAccountSDK
//
//  Created by xuyf on 14-2-14.
//  Copyright (c) 2014年 LianLian. All rights reserved.
//

#import "PxBaseEditViewController.h"

@implementation PxBaseEditViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

-(void)viewDidLoad
{
    [super viewDidLoad];
    self.view.userInteractionEnabled = YES;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideKeyBoard) name:UIKeyboardWillHideNotification object:nil];
    
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fingerTapped:)];
    
    [self.view addGestureRecognizer:singleTap];
}

-(void)fingerTapped:(UITapGestureRecognizer *)gestureRecognizer
{
    [self.view endEditing:YES];
}

-(void)hideKeyBoard
{
    if (self.contentView)
        [self.contentView setContentOffset:CGPointMake(0, 0) animated:YES];
    [self.view endEditing:YES];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    CGPoint pt = [textField convertPoint:CGPointZero toView:self.contentView];//把当前的textField的坐标映射到scrollview上
    if(self.contentView.contentOffset.y-pt.y+80<=0)//判断最上面不要去滚动
        [self.contentView setContentOffset:CGPointMake(0, pt.y-80) animated:YES];
}

@end
